package cn.chengpengper.db;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * @author huchengpeng
 * @version v1.0.0
 * @date 2023/8/20 14:27
 * @description Mybatis Plus 代码自动生成器
 */
public class MybatisPlusGenerator {
    public static void main(String[] args) {
        System.out.println("================Auto Generator Begin================");
        // 1、全局配置
        GlobalConfig config = new GlobalConfig();

        config.setAuthor("huchengpeng")
                .setOutputDir("/Users/chengpeng.hu/Shopee/IdeaProjects/Person/short-link/short-link-account/src/main/java")
                .setFileOverride(true)
                .setIdType(IdType.AUTO)
                .setDateType(DateType.ONLY_DATE)
                .setServiceName("%sService")
                .setEntityName("%sDO")
                .setBaseResultMap(true)
                .setActiveRecord(false)
                .setBaseColumnList(true);

        // 2、数据源配置
        DataSourceConfig dsConfig = new DataSourceConfig();
        dsConfig.setDbType(DbType.MYSQL)
                .setDriverName("com.mysql.cj.jdbc.Driver")
                .setUrl("jdbc:mysql://IP:3306/short-link-account?userUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai")
                .setUsername("root")
                .setPassword("PWD");

        // 3、策略配置
        StrategyConfig stConfig = new StrategyConfig();

        // 全局大写命名
        stConfig.setCapitalMode(true)
                .setNaming(NamingStrategy.underline_to_camel)
                .setEntityLombokModel(true)
                .setInclude("account", "traffic", "traffic_task");

        // 4、包名策略配置
        PackageConfig pkConfig = new PackageConfig();
        pkConfig.setParent("cn.chengpengper.shortlink")
                .setMapper("mapper")
                .setEntity("model")
                .setService("service")
                .setController("controller")
                .setXml("mapper");

        // 5、整合配置
        AutoGenerator autoGenerator = new AutoGenerator();
        autoGenerator.setGlobalConfig(config)
                .setDataSource(dsConfig)
                .setStrategy(stConfig)
                .setPackageInfo(pkConfig);

        autoGenerator.execute();
        System.out.println("================Auto Generator Finished================");
    }
}
